//
//  KDSiginedController.m
//  WangJingApp
//
//  Created by 魏强 on 17/2/6.
//  Copyright © 2017年 KDTech. All rights reserved.
//  已签收列表

#import "KDSiginedController.h"
#import "KDSignedCell.h"

@interface KDSiginedController ()<UITableViewDelegate, UITableViewDataSource>
/**  <#Description#> */
@property (nonatomic, weak) UITableView *tableView;
/**  所有已签收数据 */
@property (nonatomic, strong) NSArray *infoArr;

@property (nonatomic, copy) NSString * cellId;

@end

@implementation KDSiginedController
#pragma mark - 懒加载区
- (NSArray *)infoArr
{
    if (!_infoArr) {
        _infoArr = [[NSArray alloc]init] ;
    }
    return _infoArr;
}
#pragma mark - 生命周期区
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = BackGroundColor;
    [self setupTableView];
}
#pragma mark - 板块布置区
- (void)setupTableView{
    UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0  , 0, screenW,  self.view.height) style:UITableViewStylePlain];
    self.tableView = tableView;
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.tableFooterView = [UIView new];
    tableView.separatorColor = BackGroundColor;
    tableView.backgroundColor = BackGroundColor;
    [self.view addSubview:tableView];
//    self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 64, 0);
    self.cellId = @"KDSignedCell";
    UINib *xib = [UINib nibWithNibName:self.cellId bundle:nil];
    
    [self.tableView registerNib:xib forCellReuseIdentifier:self.cellId];
//    self.tableView.separatorColor = WQColor(245, 245, 245);
    
    self.tableView.header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadData)];
    MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
    [footer setTitle:@"" forState:MJRefreshStateIdle];
    // 设置footer
    self.tableView.footer = footer;
    [self.tableView.header beginRefreshing];
}
#pragma mark - 事件点击区

#pragma mark - 网络请求区
- (void)loadData{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.tableView.header endRefreshing];
    });
}
- (void)loadMoreData{
    
}
#pragma mark - 通知接收区

#pragma mark - UITableViewDelegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *header = [[UIView alloc]init];
    header.frame = CGRectMake(0, 0, screenW, 35);
    
    UILabel *unitLb = [self createLbWithText:@"单位"];
    unitLb.frame = CGRectMake(10, 0, 67, header.height);
    [header addSubview:unitLb];
    
    UILabel *singerLb = [self createLbWithText:@"签收人"];
    singerLb.frame = CGRectMake(CGRectGetMaxX(unitLb.frame) + 10, 0, 67, header.height);
    [header addSubview:singerLb];
    
    UILabel *timeLb = [self createLbWithText:@"签收时间"];
    CGFloat x = CGRectGetMaxX(singerLb.frame) + 10;
    timeLb.frame = CGRectMake(x, 0, screenW - x, header.height);
    [header addSubview:timeLb];
    
    return header;
}
- (UILabel *)createLbWithText:(NSString *)text{
    UILabel *lb = [[UILabel alloc]init];
    lb.text = text;
    lb.textAlignment = NSTextAlignmentCenter;
    lb.font = [UIFont systemFontOfSize:15];
    lb.textColor = WQColor(44, 44, 44);
    return lb;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 35;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    KDSignedCell *cell = [KDSignedCell cellWithTableView:tableView];
//    cell.delegate = self;
//    if (self.infoArr.count != 0) {
//        cell.model = self.infoArr[indexPath.row];
//    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
